﻿<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-content">
            <div class="panel">
                <div class="page-header">
                    <h1 class="page-title">团队添加</h1>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a class="icon wb-home" href="javascript:;">团队管理</a>
                        </li>
                        <li class="breadcrumb-item active">团队添加</li>
                    </ol>
                </div>
                <div class="panel-body">
                    <h4 class="example-title">添加团队</h4>
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label class="control-label" for="inputBasicPassword">团队名称</label>
                            <input type="text" class="form-control" id="tuanduimingcheng" name="" placeholder="团队名称" autocomplete="off" />
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="control-label" for="inputBasicPassword">团队经理</label>
                            <select class="form-control" id="tuanduijingli">
                            </select>
                        </div>
                        <div class="form-group col-sm-4" style="padding-top:27px">
                            <button typeutton" id="tuanduitingjiashuju" class="btn btn-outline btn-success" style="width: 95%;" onclick="TianJia();">添加</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row" id="tianjiahou" hidden="hidden">
                <div class="form-group col-sm-6">
                    <div class="panel">
                        <div class="panel-body">
                            <h4 class="example-title">添加团队人员</h4>
                            <div class="row">
                                <div class="form-group col-sm-6">
                                    <label class="control-label" for="inputBasicPassword">置业顾问</label>
                                    <select class="form-control" id="zhiyeguwen">
                                    </select>
                                </div>
                                <div class="form-group col-sm-6" style="padding-top:27px">
                                    <button type="button" id="bt_ChaXun" class="btn btn-block btn-success" style="width: 95%; float: left;" onclick="TianJIaZheYeGuWen()">添加</button>
                                </div>
                            </div>
                        </div>
                        <div class="panel-body" style="margin-top:-20px">
                            <table class="table table-bordered table-hover dataTable table-striped w-full text-nowrap" id="datatablezheyeguuwen" data-plugin="dataTable">
                                <thead>
                                    <tr>
                                        <th>人员名称</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tfoot>
                                    <tr>
                                        <th>人员名称</th>
                                        <th>操作</th>
                                    </tr>
                                </tfoot>
                                <tbody></tbody>
                            </table>
                        </div>
                      </div>
                  </div>
                <div class="form-group col-sm-6">
                    <div class="panel">
                        <div class="panel-body">
                            <h4 class="example-title">添加团队案场</h4>
                            <div class="row">
                                <div class="form-group col-sm-6">
                                    <label class="control-label" for="inputBasicPassword">案场名称</label>
                                    <select class="form-control" id="anchang">
                                    </select>
                                </div>
                                <div class="form-group col-sm-6" style="padding-top:27px">
                                    <button type="button" id="bt_ChaXun" class="btn btn-block btn-success" style="width: 95%; float: left;" onclick="TianJIaAnChang()">添加</button>
                                </div>
                            </div>
                        </div>
                        <div class="panel-body" style="margin-top:-20px">
                            <table class="table table-bordered table-hover dataTable table-striped w-full text-nowrap" id="datatableanchang" data-plugin="dataTable">
                                <thead>
                                    <tr>
                                        <th>案场名称</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tfoot>
                                    <tr>
                                        <th>案场名称</th>
                                        <th>操作</th>
                                    </tr>
                                </tfoot>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input hidden="hidden" id="tuanduiid">
<script type="text/javascript">
    $(document).ready(function () {
        $("#TuanDuiGuanLi").click();
        TuanduiJingLIBangDing();
    });

    function bang() {
        var lang = {
            "sProcessing": "大量处理中，请稍后...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        $("#datatablezheyeguuwen").dataTable().fnDestroy();
        $('#datatablezheyeguuwen').dataTable({
            "order": [[0, "asc"]],
            "language": lang,
            "processing": true,
            "serverSide": true,
            //"bStateSave": true,//状态保持模式
            "searching": false,//禁用搜索
            ajax: function (data, callback, settings) {
                //封装请求参数
                //console.log(data);
                var param = {};
                param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.page = (data.start / data.length) + 1;//当前页码
                param.dir = data.order[0].dir;
                param.column = data.order[0].column;
                param.tuanduiidzhi = $("#tuanduiid").val();
                //console.log(param);
                //ajax请求数据
                $.ajax({
                    type: "POST",
                    url: "../TuanDui/IniZheYeDataTable",
                    cache: false,  //禁用缓存
                    data: param,  //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        console.log(result);
                        //setTimeout仅为测试延迟效果
                        setTimeout(function () {
                            //封装返回数据
                            var returnData = {};
                            returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.total;//返回数据全部记录
                            returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.data;//返回的数据列表
                            //console.log(returnData);
                            //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕"orderable" : false
                            callback(returnData);
                        }, 200);
                    }
                });
            },
            "columns": [
                { "data": "t_RenYuanBiao.XingMing" },
                { "data": null }
            ],
            columnDefs: [{
                //   指定第最后一列
                targets: -1,
                //加下面属性 不参与排序
                sortable: false,
                render: function (data, type, row, meta) {
                     return '<button type="button" class="btn btn-outline btn-default" onclick="ZheYeShangChu(' + row.Id + ')">删除</button>';
                }
            }]
        });
    }
    function bong() {
        var lang = {
            "sProcessing": "大量处理中，请稍后...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        $("#datatableanchang").dataTable().fnDestroy();
        $('#datatableanchang').dataTable({
            "order": [[0, "asc"]],
            "language": lang,
            "processing": true,
            "serverSide": true,
            //"bStateSave": true,//状态保持模式
            "searching": false,//禁用搜索
            ajax: function (data, callback, settings) {
                //封装请求参数
                //console.log(data);
                var param = {};
                param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                param.start = data.start;//开始的记录序号
                param.page = (data.start / data.length) + 1;//当前页码
                param.dir = data.order[0].dir;
                param.column = data.order[0].column;
                param.tuanduiidzhi = $("#tuanduiid").val();
                //console.log(param);
                //ajax请求数据
                $.ajax({
                    type: "POST",
                    url: "../TuanDui/IniAnChangDataTable",
                    cache: false,  //禁用缓存
                    data: param,  //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        console.log(result);
                        //setTimeout仅为测试延迟效果
                        setTimeout(function () {
                            //封装返回数据
                            var returnData = {};
                            returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.total;//返回数据全部记录
                            returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.data;//返回的数据列表
                            //console.log(returnData);
                            //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕"orderable" : false
                            callback(returnData);
                        }, 200);
                    }
                });
            },
            "columns": [
                { "data": "t_AnChangBiao.AnChangMingCheng" },
                { "data": null }
            ],
            columnDefs: [{
                //   指定第最后一列
                targets: -1,
                //加下面属性 不参与排序
                sortable: false,
                render: function (data, type, row, meta) {
                    return '<button type="button" class="btn btn-outline btn-default" onclick="AnChangShangChu(' + row.Id + ')">删除</button>';
                }
            }]
        });
    }
    
    function TuanduiJingLIBangDing()
    {
        $.ajax({
            type: 'post',
            url: '../TuanDui/TuanDuiJingLiShuJu',
            async: false,
            dataType: 'json',
            success: function (date) {
                var ddl = $("#tuanduijingli");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].xingMing).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    }

    function BangDingZheYeGuWen() {
        $('#zhiyeguwen option').remove();
        var id = $("#tuanduiid").val();
        $.ajax({
            type: 'post',
            url: '../TuanDui/BangDingZheYe',
            async: false,
            dataType: 'json',
            data: { id: id },
            success: function (date) {
                var ddl = $("#zhiyeguwen");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].xingMing).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    }

    function BangDingAnChang() {
        $('#anchang option').remove();
        var id = $("#tuanduiid").val();
        $.ajax({
            type: 'post',
            url: '../TuanDui/BangDingAnChangShuJu',
            async: false,
            dataType: 'json',
            data: { id: id },
            success: function (date) {
                var ddl = $("#anchang");
                ddl.append("<option value='0'>请选择</option>");
                $(date).each(function (key) {
                    var opt = $("<option></option>").text(date[key].xingMing).val(date[key].id);
                    ddl.append(opt);
                })
            },
        })
    }

    function TianJia() {
        var tuanduimingcheng = $("#tuanduimingcheng").val();
        var tuanduijingli = jQuery("#tuanduijingli").val();
        if (tuanduimingcheng == "") {
            alert("团队名称不能为空");
        } else if (tuanduijingli == "0") {
            alert("团队经理不能为空");
        } else {
            $.ajax({
                type: 'post',
                url: '../TuanDui/TuanDuiTianJia',
                dataType: 'text',
                async: true,
                data: { tuanduimingcheng: tuanduimingcheng, tuanduijingli: tuanduijingli },
                success: function (result) {
                    if (result != "0") {
                        alert("添加成功");
                        $("#tuanduiid").val(result);
                        $('#tianjiahou').removeAttr("hidden");
                        BangDingZheYeGuWen();
                        BangDingAnChang();
                        document.getElementById("tuanduitingjiashuju").disabled = true; 
                    } else {
                        alert("添加失败");
                    }
                }
            });
        }
    }

    function TianJIaZheYeGuWen()
    {
        var tuanduiid = $("#tuanduiid").val();
        var zhiyeguwen = jQuery("#zhiyeguwen").val();
        if (zhiyeguwen == "0") {
            alert("请选择置业顾问");
        } else {
            $.ajax({
                type: 'post',
                url: '../TuanDui/TuanDuiRenYuanTianJia',
                dataType: 'text',
                async: true,
                data: { tuanduiid: tuanduiid, zhiyeguwen: zhiyeguwen },
                success: function (result) {
                    if (result == "1") {
                        alert("添加成功");
                        BangDingZheYeGuWen()
                        bang();
                    } else {
                        alert("添加失败");
                    }
                }
            });
        }
    }

    function TianJIaAnChang()
    {
        var tuanduiid = $("#tuanduiid").val();
        var anchang = jQuery("#anchang").val();
        if (anchang == "0") {
            alert("请选择案场");
        } else {
            $.ajax({
                type: 'post',
                url: '../TuanDui/TianJIaAnChangShuJu',
                dataType: 'text',
                async: true,
                data: { tuanduiid: tuanduiid, anchang: anchang },
                success: function (result) {
                    if (result == "1") {
                        alert("添加成功");
                        BangDingAnChang();
                        bong();
                    } else {
                        alert("添加失败");
                    }
                }
            });
        }
    }

    function ZheYeShangChu(id)
    {
        $.ajax({
            type: 'post',
            url: '../TuanDui/ZheYeShangChu',
            dataType: 'text',
            async: true,
            data: { id: id},
            success: function (result) {
                if (result == "1") {
                    alert("删除成功");
                    BangDingZheYeGuWen()
                    bang();
                } else {
                    alert("删除失败");
                }
            }
        });
    }

    function AnChangShangChu(id)
    {
        $.ajax({
            type: 'post',
            url: '../TuanDui/AnChangShangChu',
            dataType: 'text',
            async: true,
            data: { id: id},
            success: function (result) {
                if (result == "1") {
                    alert("删除成功");
                    BangDingAnChang();
                    bong();
                } else {
                    alert("删除失败");
                }
            }
        });
    }

</script>